package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.RankingBoardRewardsConf;
import com.sc.nft.entity.vo.AdminRankingBoardRewardsDetailsVO;
import com.sc.nft.mapper.RankingBoardRewardsConfMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 排行榜奖励配置表(sc_ranking_board_rewards_conf)数据DAO
 *
 * @author Sun
 * @description 由 Mybatisplus Code Generator 创建
 * @since 2023-08-03 16:44:44
 */
@Slf4j
@Repository
public class RankingBoardRewardsConfDao extends ServiceImpl<RankingBoardRewardsConfMapper, RankingBoardRewardsConf> {

    public Integer getCountByRankingBoardConfId(Long rankingBoardConfId) {
        LambdaQueryWrapper<RankingBoardRewardsConf> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(RankingBoardRewardsConf::getRankingBoardConfId, rankingBoardConfId);
        return count(wrapper);
    }

    public List<AdminRankingBoardRewardsDetailsVO> getRankingBoardRewardsDetailsById(Long rankingBoardConfId) {
        return baseMapper.getRankingBoardRewardsDetailsById(rankingBoardConfId);
    }

    /**
     * 根据排名和排行榜配置id获取排行榜收益配置
     *
     * @param rankingBoardConfId
     * @param ranking
     * @return
     */
    public RankingBoardRewardsConf getByRankingAndRankingBoardConfId(Long rankingBoardConfId, Integer ranking) {
        LambdaQueryWrapper<RankingBoardRewardsConf> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(RankingBoardRewardsConf::getRankingBoardConfId, rankingBoardConfId);
        wrapper.eq(RankingBoardRewardsConf::getRanking, ranking);
        wrapper.orderByDesc(RankingBoardRewardsConf::getId);
        wrapper.last("limit 1");
        return getOne(wrapper);
    }

    public List<RankingBoardRewardsConf> getTradingIncentiveEarnings(Long id, Integer ranking) {
        LambdaQueryWrapper<RankingBoardRewardsConf> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(RankingBoardRewardsConf::getRankingBoardConfId, id);
        // 等级大于等于最小 小于等于最大
        wrapper.le(RankingBoardRewardsConf::getRanking, ranking);
        wrapper.ge(RankingBoardRewardsConf::getRanking, ranking);
        return list(wrapper);
    }

}